package com.ylq.todolsitserver.mapper;

import com.ylq.todolsitserver.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    @Insert("INSERT INTO categories(name, color, created_time, updated_time) " +
            "VALUES(#{name}, #{color}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Category category);

    @Select("SELECT * FROM categories")
    List<Category> findAll();

    @Select("SELECT * FROM categories WHERE id = #{id}")
    Category findById(Integer id);

    @Update("UPDATE categories SET name = #{name}, color = #{color}, updated_time = NOW() WHERE id = #{id}")
    void update(Category category);

    @Delete("DELETE FROM categories WHERE id = #{id}")
    void delete(Integer id);
}